package com.penngo.gui.dfdiff.view;

import cn.hutool.core.util.StrUtil;
import com.penngo.gui.dfdiff.DFMain;


import javax.swing.*;

/**
 * 主界面右边多窗口文档区
 */
public class DesktopPane extends JDesktopPane {
    public DesktopPane() {
        setTransferHandler(DFMain.handler);
    }

    public boolean isFrameOpen(ProjectNode node){
        JInternalFrame[] frames = DFMain.desktopPane.getAllFrames();
        for(JInternalFrame frame:frames){
            if(frame instanceof DesktopFrame df){
                ProjectNode nodeTemp = df.getProjectNode();
                if(node.equals(nodeTemp)){
                    return true;
                }
            }
        }
        return false;
    }
    public boolean selectFrame(ProjectNode node){
        return selectFrame(node, null);
    }
    public boolean selectFrame(ProjectNode node, String title){
        JInternalFrame[] frames = DFMain.desktopPane.getAllFrames();
        for(JInternalFrame frame:frames){
            if(frame instanceof DesktopFrame df){
                ProjectNode nodeTemp = df.getProjectNode();
                if(node.equals(nodeTemp)){
                    if(node == nodeTemp){
                        if(StrUtil.isEmpty(title) == false){
                            df.setTitle(title);
                        }
                        df.setFrameSelected(true);
                        df.toFront();
                    }
                }
            }
        }
        return false;
    }
}
